<template>
    <div style="width:100%;height:100%;overflow:hidden">
        <weui-cell :list="cell_1_list">
        </weui-cell>
        <weui-cell :list="cell_0_list" style="max-height:calc(100% - 45px);overflow-y:auto">
        </weui-cell>
    </div>
</template>

<script>
    import WeuiCell from '../vue2componentSet/src/components/WeuiCell'
    import global from '../lib/global'
    import axios from 'axios'

    export default {
        components: {
            WeuiCell
        },
        data() {
            return {
                cell_0_list: [],
				cell_1_list: [{
					value: '添加',
					link: '#/promoter'
				}]
            }
        },
        mounted() {
            this.$store.commit('set_title', '推荐人')

            if (!this.$store.state.admin) {
                this.$router.goback()
                return
            }

            axios.post(global.server + 'getPromoter.do', {
            }).then(result => {
                var obj = result.data
                for (var i = 0; i < obj.length; ++i) {
                    for (var j = i + 1; j < obj.length; ++j) {
                        if (obj[i].returnPromoterMoney < obj[j].returnPromoterMoney ||
                            (obj[i].returnPromoterMoney == obj[j].returnPromoterMoney && obj[i].willReturnPromoterMoney < obj[j].willReturnPromoterMoney)
                        ) {
                            var tmp = obj[i]
                            obj[i] = obj[j]
                            obj[j] = tmp
                        }
                    }
                }
                obj.forEach(item => {
                    this.cell_0_list.push({
                        value: item.phone,
                        desc: item.name + '(已返' + item.returnPromoterMoney + '/待返' + item.willReturnPromoterMoney + ')',
						link: '#/promoter?phone=' + item.phone + '&name=' + item.name
                    })
                })
            })
        }
    }
</script>
